| Total Complexity | 2 |
| Total Lines | 26 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import { QueryHandler } from '@nestjs/cqrs'; |
||
| 6 | |||
| 7 | @QueryHandler(GetShootingsBySchoolQuery) |
||
| 8 | export class GetShootingsBySchoolQueryHandler { |
||
| 9 | constructor( |
||
| 10 | @Inject('IShootingRepository') |
||
| 11 | private readonly shootingRepository: IShootingRepository |
||
| 12 | ) {} |
||
| 13 | |||
| 14 | public async execute({ schoolId }: GetShootingsBySchoolQuery): Promise<ShootingSummaryView[]> { |
||
| 15 | const shootingViews: ShootingSummaryView[] = []; |
||
| 16 | const shootings = await this.shootingRepository.findBySchool( |
||
| 17 | schoolId |
||
| 18 | ); |
||
| 19 | |||
| 20 | for (const shooting of shootings) { |
||
| 21 | shootingViews.push( |
||
| 22 | new ShootingSummaryView( |
||
| 23 | shooting.getId(), |
||
| 24 | shooting.getName(), |
||
| 25 | shooting.getStatus(), |
||
| 26 | shooting.getShootingDate() |
||
| 27 | ) |
||
| 28 | ); |
||
| 29 | } |
||
| 30 | |||
| 31 | return shootingViews; |
||
| 32 | } |
||
| 34 |